import {
  CoolController,
  BaseController,
  CoolUrlTag,
  TagTypes,
  CoolTag,
} from '@cool-midway/core';
import { Body, Get, Inject, Post, Query } from '@midwayjs/core';
import { BizCustomerListService } from '../../service/list';

/**
 * app相关接口
 */
@CoolUrlTag()
@CoolController()
export class BizCustomerListAppController extends BaseController {
  @Inject()
  bizCustomerListService: BizCustomerListService;

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/loginWxMiniApp', { summary: '登录&&注册' })
  async loginWxMiniApp(
    @Body('code') code: string,
    @Body('encryptedData') encryptedData: string,
    @Body('iv') iv: string
  ) {
    return this.ok(
      await this.bizCustomerListService.loginWxMiniApp(code, encryptedData, iv)
    );
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/refreshToken', { summary: '刷新token' })
  public async refreshToken(@Body('refreshToken') refreshToken) {
    return this.ok(
      await this.bizCustomerListService.refreshToken(refreshToken)
    );
  }

  @Post('/workerCollection', { summary: '刷新token' })
  public async workerCollection(
    @Body('page') page,
    @Body('size') size,
    @Body('userId') userId
  ) {
    return this.ok(
      await this.bizCustomerListService.workerCollection(page, size, userId)
    );
  }
}
